using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Manoli.Utils.CSharpFormat;
public partial class TreeSource : System.Web.UI.Page
{
    
    protected string sourceHtml
    {
        get
        {
            return ViewState["sourceHtml"] !=null? ViewState["sourceHtml"].ToString():"";
        }
        set
        {
            ViewState["sourceHtml"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsCallback)
        {
            string[] files = Directory.GetFiles(Server.MapPath("."));
            GridControl.TreeNode node;
            node = new GridControl.TreeNode();
            node.id = "root";
            node.IsRoot = true;
            node.text = "";
            node.leaf = true;
            TreeFile.TreeNodes.Add(node);
            foreach (string file in files)
            {
                string extension = Path.GetExtension(file);
                if (extension == ".aspx" || extension == ".cs")
                {
                    node = new GridControl.TreeNode();
                    node.id = Path.GetFileName(file);
                    node.text = Path.GetFileName(file);
                    node.parentNodeId = "root";
                    node.leaf = true;
                    TreeFile.TreeNodes.Add(node);
                }

            }
        }
        

    }


    protected void TreeFile_NodeClicked(object sender, GridControl.NodeClickedEventArgs e)
    {

        string fileName = e.NodeClicked.id;
        System.IO.StreamReader read = new System.IO.StreamReader(Server.MapPath(fileName));
        string source = read.ReadToEnd();
        read.Close();
        read.Dispose();
        if (fileName.IndexOf("aspx") != -1)
        {
            CSharpFormat format = new CSharpFormat();
            sourceHtml = format.FormatCode(source);
            
        }
        else
        {
            HtmlFormat htmformat = new HtmlFormat();
            sourceHtml = htmformat.FormatCode(source);
            
        }

       
    }
}
